﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using LPV_POS.Module;
using System.Resources;
using System.Globalization;

namespace LPV_POS.mh_pos.mh_danhmuc
{
    public partial class frmDM_THE_VIP : Form
    {
        CultureInfo culture;
        thuvien tv;

        #region "Muti language"

        private void SetLanguage_banhang(string cultureName)
        {
            try
            {
                culture = CultureInfo.CreateSpecificCulture(cultureName);
                ResourceManager rm = new ResourceManager("LPV_POS.Muti_language.MyResource", typeof(mh_banhang6_PhuThu).Assembly);
                BtnOK.Text = rm.GetString("dongy", culture);
                BtnThoat.Text = rm.GetString("thoat", culture);
                label1.Text = rm.GetString("mathe", culture);
                label2.Text = rm.GetString("khachhang", culture);
                lbel_tencongty.Text = rm.GetString("thekhachhang", culture);
               
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Note");
            }

        }

        #endregion

        public frmDM_THE_VIP()
        {
            this.tv = new thuvien();
            InitializeComponent();
            culture = CultureInfo.CurrentCulture;
            InitControl();
        }

        #region 1.Khởi tạo Control

        private void InitControl()
        {
            txtMaThe.KeyDown += new KeyEventHandler(txtMaThe_KeyDown);
        }

        void txtKhachHang_GotFocus(object sender, EventArgs e)
        {
            if (TestExists_KhachHang(txtMaThe.Text))
            {
                DataSet ds = Data_KhachHang(txtMaThe.Text);
                if (ds != null)
                {
                    txtKhachHang.Text = ds.Tables[0].Rows[0]["OBJNAME"].ToString() + "";
                }
                BtnOK.Focus();
            }
            else
            {
                MessageBox_LPV.Show("Mã thẻ không tồn tại.");
            }
        }

        void txtMaThe_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                if (TestExists_KhachHang(txtMaThe.Text))
                {
                    DataSet ds = Data_KhachHang(txtMaThe.Text);
                    if (ds != null)
                    {
                        txtKhachHang.Text = ds.Tables[0].Rows[0]["OBJNAME"].ToString() + "";
                    }
                    BtnOK.Focus();
                }
                else
                {
                    MessageBox_LPV.Show("Mã thẻ không tồn tại.");
                }
                
            }
        }

        #endregion

        #region 2.Xử lý nút

        private void BtnGhiChu_Click(object sender, EventArgs e)
        {
            txtMaThe.Text = new cpublic().loadformchu_point(300, 200);
            txtMaThe.Focus();
        }

        private void BtnThoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void BtnOK_Click(object sender, EventArgs e)
        {
            if (TestExists_KhachHang(txtMaThe.Text))
                this.DialogResult = DialogResult.OK;
            else
                MessageBox_LPV.Show("Mã thẻ không tồn tại.");
        }

        #endregion

        #region 3.Hàm lấy dữ liệu từ Form Nhập thẻ và xử lý Database

        public string ShowForm()
        {
            this.ShowDialog();
            string str = "";
            //this.ShowDialog();
            str = txtMaThe.Text;

            return str;
        }

        //Lấy dữ liệu khách hàng từ ID_KHACHHANG
        private DataSet Data_KhachHang(string OBJID)
        {
           return tv.sql_SelectDataset("DM_KHACHHANG","THEKHACHHANG",OBJID);
        }

        //Kiểm tra Mã khách hàng này có tồn tại không
        private bool TestExists_KhachHang(string ID_KHACHHANG)
        {
            bool flag = false;
            DataSet ds = Data_KhachHang(ID_KHACHHANG);
            if (ds != null)
            {
                if (ds.Tables[0].Rows.Count > 0)
                    flag = true;
            }
            return flag;
        }

        #endregion

        private void txtMaThe_KeyPress(object sender, KeyPressEventArgs e)
        {
            string ss = @"~`!@#$%^&*()_-+=|\:;'<,>.?/ ";
            if (ss.IndexOf(e.KeyChar) >= 0)
                e.Handled = true;
            
        }

        private void frmDM_THE_VIP_Load(object sender, EventArgs e)
        {
            cpublic ocpublic = new cpublic();
            string str_lang = ocpublic.Registry_Get("mh_main_lang");
            if (str_lang == "")
                str_lang = "vi-VN";
            SetLanguage_banhang(str_lang);
        }

    }
}
